<template>
  <div class="home-new" ref="target">
    <HomePannel title="新鲜好物" subTitle="新鲜出炉 品质靠谱" >
      <template #right>
        <XtxMore />
      </template>
    <!-- 内容 -->
    <Transition name="fade">
      <template v-slot:default>
        <ul class="goods-list" v-if="list.length">
          <li v-for="item in list" :key="item.id">
            <RouterLink :to="`/product/${item.id}`">
              <img :src="item.picture" alt="">
              <p class="name ellipsis">{{item.name}}</p>
              <p class="price">&yen;{{item.price}}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else bg="#f0f9f4" />
      </template>
    </Transition>
    </HomePannel>
  </div>
</template>

<script>
import HomePannel from './home-pannel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hook'
// import { ref } from 'vue-demi'
import { findNew } from '@/api/home'
// import { useIntersectionObserver } from '@vueuse/core'
export default {
  name: 'HomeNew',
  components: {
    HomePannel,
    HomeSkeleton
  },
  setup () {
    // const list = ref([])

    // const target = ref(null)
    // const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    //   if (isIntersecting) {
    //     findNew().then((ret) => {
    //       list.value = ret.result
    //     })
    //     stop()
    //   }
    // })
    // return {
    //   list,
    //   target
    // }
    const { list, target } = useLazyData(findNew)
    return {
      list,
      target
    }
  }
}
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
